import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const   router = new Router({
  routes: [
    {
      path: '/login',
      name: 'login',
      component: ()=>import("@/components/login")
    },

    {
      path: '/',
      name: 'main',
      component: ()=>import("@/components/main"),
      children:[
        {
          path: 'user/list',
          name: 'user',
          component: ()=>import("@/components/user"),
          
        },
        {
          path: 'role/list',
          name: 'role',
          component: ()=>import("@/components/role"),
          
        },
      ]
    },
  ]
})



/**前置守卫 */
router.beforeEach((to, from, next) => {
  console.log(to.path!='/login')
  // console.log(store.state.sysUser)
  //判断是否登录 没有登录跳转登录页
  if(to.path=='/login'){
    next()
  }else if( localStorage.getItem("token")){
    next()
  }else{
    next("/login")
  }
});


export default router;
